package world.criver.h50909.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.criver.h50909.dao.daoHome;
import world.criver.h50909.request.reqName;
import world.criver.h50909.response.resHomeAlarm;
import world.criver.h50909.response.resHomeAllEquipmentTotal;
import world.criver.h50909.response.resHomeOneEquipmentTotal;
import world.criver.h50909.tool.toolEquipmentInfo;
import world.criver.h50909.tool.toolEquipmentState;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.TemporalAdjusters;
@Service
public class serHome implements daoHome {
    @Autowired
    private toolEquipmentState toolEquipmentState;
    @Autowired
    private toolEquipmentInfo toolEquipmentInfo;
    @Override
    public resHomeAlarm queryAlarm() {
        return new resHomeAlarm(toolEquipmentState.queryAlarms(),true);
    }

    @Override
    public resHomeOneEquipmentTotal queryRandomOneEquipmentTotal(reqName info) {
//        String name= toolEquipmentInfo.getRandomEquipment();
        String image= toolEquipmentInfo.getEquipmentImage(info.getName());
        LocalDate now=LocalDate.now();
        YearMonth ym=YearMonth.from(now);
        return new resHomeOneEquipmentTotal(info.getName(),image, toolEquipmentState.state(info.getName()),
                toolEquipmentState.queryEquipmentTotal(info.getName(),now.with(TemporalAdjusters.firstDayOfMonth()),ym.atEndOfMonth().plusDays(1)),true);
    }

    @Override
    public resHomeAllEquipmentTotal queryAllEquipmentTotal() {
        LocalDate now=LocalDate.now();
        YearMonth ym=YearMonth.from(now);
        return new resHomeAllEquipmentTotal(
                toolEquipmentState.queryAllEquipmentTotal(now.with(TemporalAdjusters.firstDayOfMonth()),ym.atEndOfMonth().plusDays(1)),true);
    }
}
